// pages/account/personalinfo.js
var app = getApp();
var dateTimePicker = require('../../utils/dateTimePicker.js');
var util = require('../../utils/util.js');
import WxValidate from '../../utils/validate';
var inputContent = {};//输入内容
var text=null;
Page({
  data: {
    time: '12:00',
    dateTimeArray: null,
    dateTime: null,
    dateTimeArray1: null,
    dateTime1: null,
    startYear: 2000,
    endYear: 2050,
    isLogin: util.isLogin(),
    date: new Date().Format("yyyy-MM-dd"),
    entranceDate: new Date().Format("yyyy"),
    credentialsIndex: 0,
    nation: ["预约中"],//预约状态
    nationIndex: 0,
    customerIndex: 0,
    customer: null
  },
  bindCustomerPickerChange: function (e) {
    console.log(e.detail.value);

    this.setData({
     customerIndex: e.detail.value
    })
    
  }, bindNationPickerChange: function (e) {
    console.log(e.detail.value);

    this.setData({
      nationIndex: e.detail.value
    })
   
  },
  onLoad: function (options) {
    
    var bb = this;
    util.https('listCall.shtml', "GET", { eid: app.globalData.myInfo.eid },
      function(res){
        
        console.log(res);
        console.log(res.data.length);
        if (res.code == 0) {
          var setInfo = new Array();
          for (var index in res.data) {
            setInfo[index] = res.data[index].cname;
            console.log(res.data[index].cname + "--" + res.data[index].cphone);
          }
          console.log(setInfo);
          bb.setData({
            customer: setInfo
          })
        }
      }
      
      )

    // 页面初始化 options为页面跳转所带来的参数
    // 获取完整的年月日 时分秒，以及默认显示的数组
    var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    // 精确到分的处理，将数组的秒去掉
    var lastArray = obj1.dateTimeArray.pop();
    var lastTime = obj1.dateTime.pop();
    this.setData({
      dateTime: obj.dateTime,
      dateTimeArray: obj.dateTimeArray,
      dateTimeArray1: obj1.dateTimeArray,
      dateTime1: obj1.dateTime
    });
  },
  
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    this.setData({
      isLogin: util.isLogin(),
      userData: wx.getStorageSync("userData") || ""//用户信息
    })


  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  wxValidate: function () {
    //验证表单
    this.WxValidate = new WxValidate({
      IDCard: { //验证规则 input name值
        required: true,
        idcard: true
      },
      Name: {
        required: true,
        minlength: 2
      },
      TelNum: {
        required: true,
        tel: true
      },
      QQNumber: {
        required: true,
        digits: true,
        minlength: 5
      },
      University: {
        required: true,
        minlength: 4
      },
      Colledge: {
        required: true
      },
      MajorCode: {
        required: true
      },
      ClassCode: {
        required: true
      },
    })

  },
  //时间类型选择
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
    inputContent[e.currentTarget.id] = this.data.date.replace(/-/g, "");
  }, 
  changeTime(e) {
    this.setData({ time: e.detail.value });
    inputContent[e.currentTarget.id] = this.data.date.time;
  },
  inputtext:function(e){
    text = e.detail.value;
    console.log(e.detail.value);
  },
  /**
   * 个人信息提交数据
   */
  personalInfoSubmit: function (e) {
    //调用验证表单方法
    var bb=this;
    const params = e.detail.value
    console.log(bb.data.nation[bb.data.nationIndex]);
    console.log(bb.data.time);
    console.log(bb.data.date);
    var ldate = bb.data.date +" "+ bb.data.time+":00";
    console.log(ldate)
    console.log(bb.data.customer[bb.data.customerIndex]);
    console.log(text);
    if (text==null){
      wx.showModal({
        title: '友情提示',
        content: "请留下用户记录哦~",
        showCancel: false,
        confirmColor: "#f26604",
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定');
          }
        }
      })
      return false
    }else{
    util.https("inertAppoin.shtml", "GET", { 
      "eid": app.globalData.myInfo.eid,
      "ldate": ldate,
      "lremark": text,
      "name": bb.data.customer[bb.data.customerIndex]
    },function(data){
      console.log(data.log);
    }
      )
    }
    }
  }
)